package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Training;
import com.qf.dao.TrainingMapper;
import com.qf.service.TrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * IntelliJ IDEA -> person
 * 2019/11/21 11:33
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Service
public class TrainingServiceImpl  implements TrainingService {
    @Autowired
    private TrainingMapper trainingMapper;
    @Override
    public PageInfo<Training> findall(int pageIndex, int pageSize, String trainingname, String  auditopinion, String  trainingdateStart, String  trainingdateEnd  ) {
        PageHelper.startPage(pageIndex,pageSize);
        Map map = new HashMap();
        map.put("trainingname",trainingname);
        map.put("auditopinion",auditopinion);
        map.put("trainingdateStart",trainingdateStart);
        map.put("trainingdateEnd",trainingdateEnd);
        List<Training> trainingList = trainingMapper.findall(map);
        PageInfo<Training> pageInfo = new PageInfo<>(trainingList);
        return pageInfo;
    }

    @Override
    public List<String> findOption() {
        return trainingMapper.findOption();
    }
@Transactional
    @Override
    public int insert(Training training) {
        return  trainingMapper.insert(training);
    }

    @Override
    public List<String> findTrainingFeedback() {
        return trainingMapper.findTrainingFeedback();
    }

    @Override
    public Training selectByPrimaryKey(int id) {
        return trainingMapper.selectByPrimaryKey(id);
    }
@Transactional
    @Override
    public int updatefeedback(String trainingfeedback, String trainingsummary, String trainingresult,int id) {
       Map map = new HashMap();
       map.put("trainingfeedback",trainingfeedback);
       map.put("trainingsummary",trainingsummary);
       map.put("trainingresult",trainingresult);
       map.put("id",id);
        return trainingMapper.updatefeedback(map);
    }

    @Override
    public int updateByPrimaryKeySelective(Training training) {
        return trainingMapper.updateByPrimaryKeySelective(training);
    }

    @Override
    public int updateByIdSetState(int id,int  state) {
        Map map = new HashMap();
        map.put("id",id);
        map.put("state",state);
        return trainingMapper.updateByIdSetState(map);
    }

}
